package com.zdkj.subway.support.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.support.dto.in.SwParamTreturnTypeDTO;
import com.zdkj.subway.support.entity.SwParamTreturnType;
import com.zdkj.subway.support.service.SwParamTreturnTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 车票上交类型表
 *
 * @author cui_com
 * @date 2020-01-08 17:13:41
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swparamtreturntype")
@Api(value = "swparamtreturntype", tags = "车票上交类型表管理")
public class SwParamTreturnTypeController {

    private final SwParamTreturnTypeService swParamTreturnTypeService;

    /**
     * 分页查询
     *
     * @param page               分页对象
     * @param swParamTreturnType 车票上交类型表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getSwParamTreturnTypePage(Page page, SwParamTreturnType swParamTreturnType) {
        return R.ok(swParamTreturnTypeService.page(page, Wrappers.query(swParamTreturnType)));
    }


    /**
     * 通过id查询车票上交类型表
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(swParamTreturnTypeService.getById(id));
    }

    /**
     * 新增车票上交类型表
     *
     * @param swParamTreturnType 车票上交类型表
     * @return R
     */
    @ApiOperation(value = "新增车票上交类型表", notes = "新增车票上交类型表")
    @SysLog("新增车票上交类型表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_treturn_type_add')")
    public R save(@RequestBody SwParamTreturnTypeDTO swParamTreturnType) {
        SwParamTreturnType defaultObj = ObjectUtils.getDefaultObj(SwParamTreturnType.class);
        BeanUtils.copyProperties(swParamTreturnType, defaultObj);
        return R.ok(swParamTreturnTypeService.save(defaultObj));
    }

    /**
     * 修改车票上交类型表
     *
     * @param swParamTreturnType 车票上交类型表
     * @return R
     */
    @ApiOperation(value = "修改车票上交类型表", notes = "修改车票上交类型表")
    @SysLog("修改车票上交类型表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_treturn_type_edit')")
    public R updateById(@RequestBody SwParamTreturnTypeDTO swParamTreturnType) {
        SwParamTreturnType obj = new SwParamTreturnType();
        BeanUtils.copyProperties(swParamTreturnType, obj);
        return R.ok(swParamTreturnTypeService.updateById(obj));
    }

    /**
     * 通过id删除车票上交类型表
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除车票上交类型表", notes = "通过id删除车票上交类型表")
    @SysLog("通过id删除车票上交类型表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('support_sw_param_treturn_type_del')")
    public R removeById(@PathVariable Integer id) {
        return R.ok(swParamTreturnTypeService.removeById(id));
    }

}
